<template>
	<view v-if="finance">
		<view class="bg-white padding-lr-xl padding-tb" @click="bankShow=true">
			<u-cell-group>
				<u-cell-item title="提现到" :value="currentBank?currentBank.bank_name:'选择账户'"></u-cell-item>
			</u-cell-group>
			<view class="flex-col align-center">
				<view class="my-card" v-if="currentBank">
					<image class="bg" :src="currentBank.icon"></image>
					<view class="main">
						<view class="name">{{currentBank.bank_name}}</view>
						<view class="number">{{currentBank.hide_card_no}}</view>
					</view>
				</view>
			</view>
		</view>

		<u-popup class="pop-coupon" v-model="bankShow" mode="bottom" width="670" height="800" border-radius="16">
			<view class="flex-col align-center">
				<view class="my-card" v-for="i in bank" :key="i.id" @click="setBank(i)">
					<image class="bg" :src="i.icon"></image>
					<view class="main">
						<view class="name">{{i.bank_name}}</view>
						<view class="number">{{i.hide_card_no}}</view>
					</view>
				</view>
			</view>
		</u-popup>

		<u-gap height="40"></u-gap>

		<view class="bg-white padding-xl">
			<view>提现金额</view>
			<input class="ipt" v-model="form.amount" type="number">

			<view>
				<view>{{finance.balance}}</view>
				<view class="text-blue" @click="form.amount=finance.balance">全部提取</view>
			</view>
			<view class="text-right text-sm text-gray">
				提现手续费5%
			</view>
		</view>

		<my-btn gold size="sm" style="margin: 60rpx auto;" @click="submit">提现</my-btn>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					amount: 0,
					account: ''
				},
				finance: '',
				bank: [],
				bankShow: false,
				currentBank: ''
			};
		},
		onShow() {
			this.getData()
			this.getList()
		},
		methods: {
			submit() {
				uni.showLoading({
					title: '请稍等...',
					mask: true
				})
				this.$u.post('/finance/balance/draw', this.form).then(res => {
					this.$msg(res.data.msg)
					this.getData()
				})
			},
			getData() {
				this.$u.get('/finance/balance').then(res => {
					this.finance = res.data.result.finance
				})
			},
			getList() {
				this.$u.get('/finance/account/bank').then(res => {
					this.bank = res.data.result.bank
				})
			},
			setBank(i) {
				this.currentBank = i
				this.form.account = JSON.stringify(i)
				this.bankShow = false
			}
		}
	}
</script>

<style lang="scss">
	.ipt {
		margin: 40rpx 0;
		width: 400rpx;
		height: 80rpx;
		padding: 0 16rpx;
		font-size: 48rpx;
		background: rgba(245, 245, 245, 1);
		border-radius: 4rpx;
		border: 2rpx solid rgba(153, 153, 153, 1);
	}

	.quick {
		height: 380rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-items: space-around;

		.box {
			width: 200rpx;
			height: 100rpx;
			border-radius: 8rpx;
			border: 2rpx solid rgba(153, 153, 153, 1);
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.my-card {
		width: 670rpx;
		height: 206rpx;
		border-radius: 8rpx;
		overflow: hidden;
		position: relative;
		margin-top: 32rpx;
	
		.bg {
			position: absolute;
			width: 100%;
			height: 100%;
			z-index: 1;
		}
	
		.main {
			width: 100%;
			height: 100%;
			position: relative;
			display: flex;
			flex-direction: column;
			z-index: 2;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			letter-spacing: 2rpx;
			color: #fff;
	
			.name {
				height: 106rpx;
				line-height: 106rpx;
				padding-left: 120rpx;
				font-size: 32rpx;
			}
	
			.number {
				height: 100rpx;
				padding-left: 80rpx;
				font-size: 50rpx;
			}
		}
	}
</style>
